package com.eb.controller;

import com.eb.pojo.MiaoshaUser;
import com.eb.pojo.Result;
import com.eb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public List<MiaoshaUser> list(){
        return userService.list();
    }

    @PostMapping("/login")
    public Result login(@RequestBody MiaoshaUser user){

        int i= userService.login(user);
        if (i==1){
            return new Result(true,"登录成功");
        }else {
            return new Result(false,"登录失败");
        }

    }
    @PostMapping
    public Result zc(@RequestBody MiaoshaUser user){
        try {
            userService.zc(user);
            return new Result(true,"注册成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"注册失败");
        }
    }
    @GetMapping("/username")
    public MiaoshaUser user(){
        return userService.user();
    }
}